/**
 * <p>功能:系统管理模块-资源管理-菜单资源 <p>
 * @extends Ext.tab.Panel #e8edf0
 * @author wys
 */
Ext.define('Jason.view.protal.module.systemManager.sources.menus.MainView', {
    extend: 'Ext.tree.Panel',
    border: true,
    xtype: 'sysManagerSoucesMenuMainView',
    requires: [
        'Ext.tree.*',
        'Ext.form.*',
        'Wys.form.field.IconField',
        'Wys.grid.column.Command',
        'Ext.form.RadioGroup',
        'Wys.combobox.ComboTree',
        'Jason.view.protal.module.systemManager.sources.menus.MainCtrl',
        'Jason.view.protal.module.systemManager.sources.menus.MainViewModel',
        'Jason.store.protal.module.systemManager.sources.menus.MenuStore'
    ],
    controller: 'sources_menus_MainViewCtrl',
    itemId: 'sysManagerSoucesMenuMainView',
    viewModel: { type: 'sources_menus_MainViewModel' },
    bind: '{menuStore}',
    listeners: {
        itemdblclick: 'onEditButtonClick'
    },
    columns: [
        {
            xtype: 'treecolumn', text: '标题', flex: 3, dataIndex: 'text', align: 'left', renderer: function (v, mate) {
                mate.style = "font-weight:bold;";
                return v;
            }
        },
        {
            text: '图标', width: 50, dataIndex: 'icon', menuDisabled: true, align: 'center',
            renderer: function (v) { return '<i class="' + v + '"></i>'; }
        },
        { text: '路由', flex: 2, dataIndex: 'routeId', menuDisabled: true },
        { text: '权重', width: 70, dataIndex: 'order', menuDisabled: true, align: 'center' },
        {
            text: '类型', width: 80, dataIndex: 'extendclass', align: 'center', renderer: function (v, mate) {
                mate.style = "text-align:center;";
                return v === 'menu' ? '<div class="custom-tag custom-tag-success">菜单</div>' : v === 'modules' ? '<div class="custom-tag custom-tag-success">模块</div>' : ' ';
            }
        },
        { text: '创建日期', dataIndex: 'createDate', width: 135, xtype: 'datecolumn', format: 'Y-m-d H:i' },
        {
            text: '操作', width: 127, xtype: 'command', align: 'center',
            commands: [
                { command: "init", text: '<i class="fa fa-cogs"></i>', tooltip: { text: '初始化权限' }, cls: 'radiusBtn command-info-color', hidden: true },
                { command: "modify", text: "<i class='fa fa-edit'></i>", tooltip: { text: '编辑' }, cls: 'radiusBtn command-modify-color' },
                { command: "remove", text: "<i class='fa fa-trash'></i>", tooltip: { text: '删除' }, cls: 'radiusBtn command-remove-color' }
            ],
            prepareCommand: function (grid, command, record, row) {
                //这里可以去控制操作按钮的显示隐藏
                if (record.get('extendclass') === 'menu' && record.get('initMenu') === 0 && command.command === 'init') {
                    command.hidden = false;
                }
            },
            listeners: {
                command: 'onGridCommand'
            }
        },
        { text: ' ', width: 15 }
    ],
    dockedItems: [{
        xtype: 'toolbar',
        dock: 'top',
        items: [{
            xtype: 'segmentedbutton',
            items: [{
                xtype: 'newbutton',
                rightCode: 'MENUSMANAGER'
            }/*, {
                xtype: 'deletebutton',
                rightCode: 'MENUSMANAGER'
            }*/]
        }, '->', {
            xtype: 'button',
            iconCls: 'fa fa-refresh',
            rightCode: 'MENUSMANAGER',
            tooltip: '点击重新加载列表数据',
            handler: function (btn) {
                var selfGridView = btn.up('#sysManagerSoucesMenuMainView'),
                    selfGridViewStore = selfGridView.getStore();
                Ext.apply(selfGridViewStore.proxy.extraParams, {});
                selfGridViewStore.currentPage = 1;
                selfGridViewStore.reload();
            }
        }]
    }]
});